package com.li.springboard.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
//@EnableWebMvc   //导入了一个类Delegatin
public class MyMvcConfig implements WebMvcConfigurer {
    /**
     * 添加视图控制器
     */

    @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("index");
                registry.addViewController("/index.html").setViewName("index");
                registry.addViewController("/main.html").setViewName("dashboard");
                registry.addViewController("/customers.html").setViewName("customer");
    }


    /**
     *自定义的国际化组件生效
     */
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocalResolver();
    }


    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
                // 添加拦截器
        registry.addInterceptor(new MyHandle())
                //添加路径模式
                .addPathPatterns("/**")
                //排除拦截路径
                .excludePathPatterns("/index.html","/","/user/login","/css/*","/js/**","/img/**");
    }
}
